package com.stylefeng.guns.modular.train.service.impl;

import com.alibaba.fastjson.JSON;
import com.stylefeng.guns.common.constant.bean.EmpPointPojo;
import com.stylefeng.guns.common.constant.bean.PointTypePojo;
import com.stylefeng.guns.common.persistence.dao.EmployeeMapper;
import com.stylefeng.guns.common.persistence.model.EmpPoints;
import com.stylefeng.guns.common.persistence.dao.EmpPointsMapper;
import com.stylefeng.guns.common.persistence.model.Employee;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.modular.train.service.IEmpPointsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.*;

/**
 * <p>
 * 员工积分 服务实现类
 * </p>
 *
 * @author rockjh
 * @since 2018-01-31
 */
@Service
public class EmpPointsServiceImpl extends ServiceImpl<EmpPointsMapper, EmpPoints> implements IEmpPointsService {

    @Autowired
    private EmpPointsMapper empPointsMapper;

    @Override
    public EmpPoints createInstance(Employee employee) {
        EmpPoints empPoints=new EmpPoints();
        empPoints.setModularPonit(JSON.toJSONString(new PointTypePojo()));
        empPoints.setEmpCode(employee.getEmpCode());
        empPoints.setEmpName(employee.getEmpName());
        empPoints.setTotalPoint(0.0);
        empPoints.setYear(DateUtil.getYear(new Date()));
        return empPoints;
    }

    @Override
    public List<EmpPoints> selectByYearInCode(String year, List<String> empCodes) {
        List<EmpPoints> pointss = new ArrayList<>();
        if(CollectionUtils.isEmpty(empCodes)){
            return pointss;
        }else{
            return empPointsMapper.selectByYearInCode(year,empCodes);
        }

    }

    @Override
    public List<EmpPointPojo> selectEmpByYearInCode(String year, List<String> empCodes) {
        List<EmpPointPojo> pointss = new ArrayList<>();
        if(CollectionUtils.isEmpty(empCodes)){
            return pointss;
        }else{
            return empPointsMapper.selectEmpByYearInCode(year,empCodes);
        }

    }

}
